<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/13 0013
 * Time: 下午 1:56
 */

namespace app\admin\controller;

use app\api\controller\BaseController;
use think\Controller;


/**
 * 商户控制器
 * Class Tenant
 * @package app\admin\controller
 */
class Tenant extends Base {

    //商户充值
    public function index(){
        $tenantId  = session('TENANT_ID');
        $tenantModel = new \app\admin\model\Tenant();
        $tenant = $tenantModel->findTenantDetail($tenantId);
        $store = \app\admin\model\Store::where(['tenantId'=>$tenantId,'isActive'=>1])->select();
        $this->assign('store',$store);
        $this->assign("balance",$tenant->balance/100 );
        $this->assign('dadaBalance',$tenant->dadaBalance/100);
        return $this->fetch();
    }

//    public function tenant() {  //首页数据
//        $tenantList = \app\admin\model\Tenant::where('isActive',1)->column('id');
//        // $tenantList = \app\admin\model\Tenant::where('isActive',1)->where('id','cPyzu8PLQ8SaeHXx2REqUA')->column('id');
//        foreach ($tenantList as $tenantId) {
//            $find = \app\admin\model\Wxframeconf::where('tenantId',$tenantId)->where('storeId','not null')->find();
//            if($find) {
//                echo '此店铺已有最新首页数据'.'<hr>';
//                continue;
//            }
//
//            $store = \app\admin\model\Store::where('tenantId',$tenantId)->column('id');
//            $storeId = $store[0];  //得到第一个门店id
//
//            $frame = \app\admin\model\Wxframeconf::where(['type'=>['in','3,4,6,7'],'tenantId'=>$tenantId])->column('id');
//
//            foreach ($frame as $f) {
//                if(\app\admin\model\Wxcomponentconf::where('frameId',$f)->delete()) {
//                    echo "删除wxcomponentconf 中frameId 为".$f."的数据成功<br/>";
//                } else {
//                    echo "删除wxcomponentconf 中frameId 为".$f."的数据<span style='color:red'>失败</span><br/>";
//                }
//            }
//            $del1 = \app\admin\model\Wxframeconf::where(['type'=>['in','3,4,6,7'],'tenantId'=>$tenantId])->delete();  //删除3.0不存在或已改动的类型，如拼团模块，商品模块，分割线，文章
//            if($del1) {
//                echo "删除Wxframeconf部分数据成功<br/>";
//            } else {
//                echo "删除Wxframeconf部分数据<span style='color:red'>失败</span><br/><br/>";
//            }
//
//            $update1 = \app\admin\model\Wxframeconf::where('tenantId',$tenantId)->update(['storeId'=>$storeId]);
//            if($update1) {
//                echo "更新Wxframeconf门店ID成功<br/>";
//            } else {
//                echo "删除Wxframeconf门店ID<span style='color:red'>失败</span><br/><br/>";
//            }
//            echo "<hr>";
//        }
//    }

    /**
     * 充值记录 列表
     * @return \think\response\Json
     */
    public function getRechargeLogList(){
        $request = $this->request;
        $param = $request->param();
        $model = db('servicebuyorder');

        // 每页起始条数
        $start = $param['start'];
        // 每页显示条数
        $length = $param['length'];

        $where = [
            'tenantId' => session('TENANT_ID'),
            'status' => 1
        ];

        $list = $model->where($where)->limit($start, $length)->select();
        $count = $model->where($where)->count();

        $result = [
            'status' => '1',
            'draw' => $param['draw'],
            'data' => $list,
            'recordsFiltered' => $count,
            'recordsTotal' => $count,
        ];

        return json($result);
    }

}